package com.xyz.rok.tools.service.impl;

import com.xyz.rok.tools.mapper.ConfigMapper;
import com.xyz.rok.tools.model.Config;
import com.xyz.rok.tools.service.ConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ConfigServiceImpl implements ConfigService {

    @Resource
    private ConfigMapper configMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return configMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Config record) {
        return configMapper.insert(record);
    }

    @Override
    public int insertSelective(Config record) {
        return configMapper.insertSelective(record);
    }

    @Override
    public Config selectByPrimaryKey(Integer id) {
        return configMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Config record) {
        return configMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Config record) {
        return configMapper.updateByPrimaryKey(record);
    }

    @Override
    public Map<String, String> selectConfig() {
        List<Config> configs = configMapper.selectConfig();
        Map<String, String> map = new HashMap<>(16);
        for (Config config : configs) {
            map.put(config.getKey(), config.getValue());
        }
        return map;
    }

    @Override
    public Config selectServerConfig(Integer serverId, String key) {
        return configMapper.selectByKey(serverId + "-" + key);
    }

    @Override
    public Config selectByKey(String key) {
        return configMapper.selectByKey(key);
    }

    @Override
    public List<Config> selectByLikeKey(String key) {
        return configMapper.selectByLikeKey(key);
    }

}
